﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Power.Model;
using Power.DAL;

namespace Power
{
    /// <summary>
    /// ReportList.xaml 的交互逻辑
    /// </summary>
    public partial class ReportList : Window
    {
        public string username
        {
            get;
            set;
        }

        public string device
        {
            get;
            set;
        }


        public ReportList()
        {
            InitializeComponent();
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {



            ReportM temp = (ReportM)dgreport.SelectedItem;



            string timenow=DateTime.Now.ToShortDateString();







            var printDialog = new System.Windows.Controls.PrintDialog();


            string mendreport = "客户名:" + username + "\n" + "\n" +
                "设备号:" + temp.Device + "\n" + "\n" +
                "主题:" + temp.Theme + "\n" + "\n" +
                "内容:" + temp.BoText + "\n" + "\n" +
                "费用:" + temp.Fee + "\n" + "\n" +
                "时间:"+timenow+"\n"


;

            Run run = new Run(mendreport);
            TextBlock temptext = new TextBlock();
            temptext.Inlines.Add(run);
            temptext.Margin = new Thickness(20, 5, 5, 5);
            temptext.TextWrapping = TextWrapping.Wrap;
            temptext.LayoutTransform = new ScaleTransform(1, 1);
            Size pageSize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);
            temptext.Measure(pageSize);
            temptext.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));



            //设置打印机
            Nullable<Boolean> print = printDialog.ShowDialog();
            if (print == true)
            {

                //打印

                printDialog.PrintVisual(temptext, "测试");
            }



















        }

        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            List<ReportM> Reportlist = new List<ReportM>();


            ReportM[] repta = new ReportDAL().ListToFind(device);

            foreach (ReportM repone in repta)
            {
                ReportM p = new ReportM();
                p.Id = repone.Id;
                p.Device = repone.Device;
                p.BoText = repone.BoText;
                p.Fee = repone.Fee;
                p.Theme = repone.Theme;
                
                Reportlist.Add(p);

            }
            dgreport.ItemsSource = Reportlist;

        }
    }
}
